import { CommonEntity } from '../../../dto/common.entity';
import { IsNotEmpty, Min } from 'class-validator';
import { Column, Entity } from 'typeorm';

export enum productStatustype {
  PUTAWAY = 'putaway',
  UN_PUTAWAY = 'un_putaway',
}

@Entity('product')
export class Product extends CommonEntity {
  @Column({
    comment: '名称',
  })
  @IsNotEmpty()
  name: string;

  @Column({
    comment: '描述',
    nullable: true,
  })
  desc: string;

  @Column({
    comment: '库存总数',
    default: 0,
  })
  stock: number;

  @Column({
    comment: '上下架状态',
    default: productStatustype.UN_PUTAWAY,
  })
  @IsNotEmpty()
  status: string;

  @Column({
    comment: '售出总数',
    default: 0,
  })
  sellNum: number;

  @Column({
    comment: '每人限购数量',
    default: -1,
  })
  limitBuyNum: number;

  @Column({
    comment: '封面',
  })
  cover: string;

  @Column({
    comment: '头部banner图',
  })
  bannerUrl: string;

  @Column({
    comment: '分类',
  })
  type: string;

  @Column({
    comment: '原价',
    type: 'float',
  })
  @IsNotEmpty()
  @Min(0.01)
  originPrice: number;

  @Column({
    comment: '优惠价格',
    type: 'float',
  })
  @IsNotEmpty()
  @Min(0.01)
  preferentialPrice: number;

  @Column({
    comment: '所属机构',
  })
  @IsNotEmpty()
  orgId: string;

  @Column({
    comment: '消费卡',
    nullable: true,
    length: 9999,
  })
  cards: string;
}
